<template>
    <div class="mod-prod-prodTag">
        <avue-crud ref="crud" :page="page" :data="dataList" :table-loading="dataListLoading" :option="tableOption"
            @search-change="searchChange" @on-load="getDataList" @refresh-change="refreshChange" @row-update="addUpdate"
            @row-save="rowSave">
            <template slot-scope="scope" slot="menu">
                <el-button type="text" size="mini" icon="el-icon-search"
                    @click="openOldYears(scope.row)">历年查询</el-button>
            </template>
        </avue-crud>
        <old-years ref="oldYearsRef"></old-years>
    </div>
</template>

<script>
import OldYears from './OldYears.vue'
import { tableOption } from '@/crud/manage/year'
import somthing from '@/views/modules/manage/plan/audit.vue'
export default {
    components: {
        somthing,
        OldYears

    },
    data() {
        return {
            page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 10 // 每页显示多少条
            },
            dataList: [],
            dataListLoading: false,
            tableOption: tableOption,
            permission: {
                delBtn: this.isAuth('prod:prodTag:delete')
            },
        }
    },
    created() {
    },
    mounted() {
    },
    methods: {
        openOldYears() {
            this.$refs.oldYearsRef.init()
        },
        getDataList(page, params, done) {
            this.dataListLoading = true
            this.dataListLoading = true
            this.$http({
                url: this.$http.adornUrl('/crm/year/plan/page'),
                method: 'get',
                params: this.$http.adornParams(Object.assign({
                    current: page == null ? this.page.currentPage : page.currentPage,
                    size: page == null ? this.page.pageSize : page.pageSize
                }, {
                    // planType: "1",
                    ...params
                }))
            }).then(({ data }) => {
                this.dataList = data.obj.records
                console.log('🚀 ~ this.dataList', this.dataList)
                this.page.total = data.obj.total
                this.dataListLoading = false
                if (done) {
                    done()
                }
            })
        },
        rowSave(form, done, loading) {
            console.log('🚀 ~ form', form)
            this.$http({
                url: this.$http.adornUrl('/crm/year/plan/addPlanCustomer'),
                method: 'post',
                data: this.$http.adornData({
                    ...form,
                    planType: "1"
                })
            }).then(({ data }) => {
                this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                        if (done) {
                            done()
                        }
                        this.getDataList(this.page)
                    }
                })
            }).catch(() => {
                if (done) {
                    done()
                }
            })
        },
        addUpdate() {

        },
        // 新增 / 修改
        addOrUpdateHandle(id) {
            this.addOrUpdateVisible = true
            this.$nextTick(() => {
                this.$refs.addOrUpdate.init(id)
            })
        },
        deleteHandle(id) {
            this.$confirm('确定进行删除操作?', '友情提醒', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http({
                    url: this.$http.adornUrl('/prod/prodTag/' + id),
                    method: 'delete',
                    data: this.$http.adornData({})
                }).then(({ data }) => {
                    this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                            this.getDataList(this.page)
                        }
                    })
                })
            }).catch(() => { })
        },
        /**
         * 刷新回调
         */
        refreshChange() {
            this.getDataList(this.page)
        },
        searchChange(params, done) {
            this.getDataList(this.page, params, done)
        }
    }
}
</script>

<style lang="scss" scoped></style>
